package pers.cz.common.connect.localfile;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.cz.common.connect.Connection;
import pers.cz.common.exception.ExceptionUtil;

import java.io.*;
import java.sql.SQLException;

/**
 * @program: Jef-orm
 * @description: 本地文件连接
 * @author: Cheng Zhi
 * @create: 2023-09-02 22:33
 **/
public class LocalFileConnection extends Connection {

    Logger logger = LoggerFactory.getLogger(LocalFileConnection.class);

    private InputStream inputStream;

    public LocalFileConnection(File file) {
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            inputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void close() {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Object getConnectin() {
        return this.inputStream;
    }
}
